﻿/*!
 *  Copyright (c), 上海沃恩信息科技有限公司.
 *  All rights reserved.
 *  Licensed under BSD (https://www.pittypat.work/bsd.html).
 */

using System.IO;
using Pittypat;

namespace Waln.Authority.Authentication
{
    sealed class AuthorityUser : IUser
    {
        private Data.User user;
        internal AuthorityUser(Data.User user)
        {
            this.user = user;
        }

        #region IUser

        uuid? IUser.Id
        {
            get
            {
                return this.user.Id;
            }
        }

        @string? IUser.LoginName
        {
            get
            {
                return this.user.LoginName;
            }
        }

        @string? IUser.FriendlyName
        {
            get
            {
                return this.user.Name;
            }
        }

        @string? IUser.FaceUrl
        {
            get
            {
                return this.user.FaceUrl;
            }
        }

        @string? IUser.LoginHomeUrl
        {
            get
            {
                return this.user.LoginHomeUrl;
            }
        }

        @string? IUser.SettingUrl
        {
            get
            {
                return "~/com/waln/authority/profile/index.html";
            }
        }

        @datetime? IUser.Now
        {
            get
            {
                return this.user.Now;
            }
        }

        void IJson.Write(TextWriter writer)
        {
            if (writer == null)
            {
                throw new global::System.ArgumentNullException("writer");
            }

            writer.Write('{');

            // Id
            writer.Write("\"id\":");
            this.user.Id.Write(writer);
            writer.Write(',');

            // 登录名称
            writer.Write("\"loginName\":");
            this.user.LoginName.Write(writer);
            writer.Write(',');

            // 编号
            writer.Write("\"no\":");
            this.user.No.Write(writer);
            writer.Write(',');

            // 用户名称
            writer.Write("\"name\":");
            this.user.Name.Write(writer);
            writer.Write(',');

            // 头像路径
            writer.Write("\"faceUrl\":");
            this.user.FaceUrl.Write(writer);
            writer.Write(',');

            // 手机号码
            writer.Write("\"mobile\":");
            this.user.Mobile.Write(writer);
            writer.Write(',');

            // 电子邮件地址
            writer.Write("\"email\":");
            this.user.Email.Write(writer);
            writer.Write(',');

            // 创建时间
            writer.Write("\"createTime\":");
            this.user.CreateTime.Write(writer);
            writer.Write(',');

            // 锁定时间
            writer.Write("\"lockTime\":");
            this.user.LockTime.Write(writer);
            writer.Write(',');

            // 登录时间
            writer.Write("\"loginTime\":");
            this.user.LoginTime.Write(writer);
            writer.Write(',');

            // 登录后首页
            writer.Write("\"loginHomeUrl\":");
            this.user.LoginHomeUrl.Write(writer);
            writer.Write(',');

            // 登录后首页说明
            writer.Write("\"loginHomeDescription\":");
            this.user.LoginHomeDescription.Write(writer);
            writer.Write(',');

            // 设置用户资料的路径
            writer.Write("\"settingUrl\":\"{0}\",", ((IUser)this).SettingUrl);

            // 服务器当前时间
            writer.Write("\"now\":");
            this.user.Now.Write(writer);

            writer.Write('}');
        }

        #endregion
    }
}
